const app = require("express")()
const session = require("express-session")
const borderParser = require("body-parser")
const router = require("./router.js")

// 设置header
app.all('*', function (req, res, next) {
    res.header("Content-Type","application/json;charset=utf-8");
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
    res.header("Access-Control-Allow-Headers", "Content-Type,Authorization,X-Requested-With");
	res.header("X-Powered-By",'3.2.1');
    next();
});

// express-session
app.use(session({
    secret: '#########',
    name: "sessionId",
    resave: false,
    saveUninitialized: false,
    cookie: {
        macAge: 1000 * 60 * 60 * 24,
    }
}))

// 挂在参数处理中间件 (post)
app.use(borderParser.urlencoded({
    extended: false
}));
app.use(borderParser.json())

app.use("/user", router)

app.listen(3000, "192.168.43.167", () => {
    console.log("Running...");
})